package com.newtouch.bxzs.database.synchronize.batch.writer;

import com.newtouch.bxzs.common.base.model.CooperationCompanyOrganization;
import com.newtouch.bxzs.common.base.model.Organization;
import com.newtouch.bxzs.database.mapper.OrganizationMapper;
import com.newtouch.bxzs.database.synchronize.mapper.OrganizationOppositeMapper;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 组织架构同步入库
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/7 10:45</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
@SuppressWarnings("unchecked")
public class WriterOrganization {

    @Autowired
    private OrganizationMapper organizationMapper;

    @Autowired
    private OrganizationOppositeMapper organizationOppositeMapper;

    /**
     * 同步本端机构数据至数据库
     * @return ItemWriter
     */
    public ItemWriter<Organization> addOwnOrganList(){
        return list -> organizationMapper.addOrganization((List<Organization>) list,new Date());
    }

    /**
     * 同步对端机构数据至数据库
     * @return ItemWriter
     */
    public ItemWriter<CooperationCompanyOrganization> addOppositeOrganList(){
        return list -> organizationOppositeMapper.addOrganizationOpposite((List<CooperationCompanyOrganization>) list);
    }
}
